package com.rabbitmq.topic;

import com.rabbitmq.client.Channel;
import com.rabbitmq.client.Connection;
import com.rabbitmq.utils.RabbitMqUtils;

import java.io.IOException;

/**
 * @author lipengwei
 */
public class Provider {

    public static void main(String[] args) throws IOException {
        Connection connection = RabbitMqUtils.getConnection();
        Channel channel = connection.createChannel();
        // 声明交换机以及交换机类型 topic
        channel.exchangeDeclare("topics", "topic");
        // 发送消息
        String routingKey= "user.save";

        channel.basicPublish("topics", routingKey, null,
                ("这是 topic 动态路由模型发布的基于 router key：" + routingKey).getBytes());

        RabbitMqUtils.closeChannelAndConnection(channel, connection);

        System.out.println("消息发布成功！");
    }
}
